// web/src/app/api/(learn)/course/route.ts
import {NextRequest, NextResponse} from "next/server";
import {auth} from "@/auth";
import {db} from "@/lib/db";

export async function POST(req: NextRequest) {
    try {
        const session = await auth()
        const user = session?.user
        const {title} = await req.json()

        if (!user) {
            return new NextResponse('Unauthorized', {status: 401})
        }

        const course = await db.course.create({
            data: {
                userId: user.id!,
                title
            }
        })

        return NextResponse.json(course)
    } catch (err) {
        console.error(err)
        return new NextResponse('Internal Error', {status: 500})
    }
}